package com.in.mobilerechargedth;

import java.util.ArrayList;
import java.util.List;

import com.in.mobilerechargedth.adapter.FourthRechargeDetailScreenListViewAdapter;
import com.in.mobilerechargedth.constant.ConstantVariables;
import com.in.mobilerechargedth.model.RechargeModel;

import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class FourthRechargeDetailScreenActivity extends BaseActivity {

    List<RechargeModel> rechargeDetails;
    ListView lvDetail;
    TextView txtEmpty;
    int operatorId = 0;
    Button backbtn;

    List<RechargeModel> listRechargeModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fourth_recharge_detail_screen);
        String amount = getIntent().getStringExtra(
                ConstantVariables.EXTRA_AMOUNT);
        String circleName = getIntent().getStringExtra(
                ConstantVariables.EXTRA_CIRCLE);
        String strOperatorId = getIntent().getStringExtra(ConstantVariables.OPERATOR_ID);
        operatorId = Integer.parseInt(strOperatorId);
        rechargeDetails = new ArrayList<RechargeModel>();
        backbtn = (Button) findViewById(R.id.backbtn);
        backbtn.setVisibility(View.VISIBLE);
        backbtn.setOnClickListener(this);
        listRechargeModel = FourthScreenActivity.listRechargeModel;


        for (RechargeModel rechargeModel : listRechargeModel) {
            if (amount.equals(rechargeModel.getAmount()) && circleName.equals(rechargeModel.getCircleName()) && operatorId == rechargeModel.getOperatorId()) {
                RechargeModel detail = new RechargeModel();
                detail.setAmount(rechargeModel.getAmount());
                detail.setCircleName(rechargeModel.getCircleName());
                detail.setValidity(rechargeModel.getValidity());
                detail.setOfferdetails(rechargeModel.getOfferdetails());
                rechargeDetails.add(detail);
            }
        }

        if (rechargeDetails != null && rechargeDetails.size() > 0) {
            lvDetail = (ListView) findViewById(R.id.lvRechargePlan);
            FourthRechargeDetailScreenListViewAdapter adapter = new FourthRechargeDetailScreenListViewAdapter(
                    rechargeDetails, FourthRechargeDetailScreenActivity.this);
            lvDetail.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        } else {

            lvDetail = (ListView) findViewById(R.id.lvRechargePlan);
            txtEmpty = (TextView) findViewById(R.id.txtEmpty);
            txtEmpty.setVisibility(View.VISIBLE);
            lvDetail.setVisibility(View.GONE);
        }

        setupAdmob();
        share();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        super.onClick(v);
        switch (v.getId()) {
        case R.id.backbtn:
            this.onBackPressed();
            break;
        }
    }
}
